const bd = require('./bd.js')
const http = require('http')
const servers =http.createServer()

servers.listen(7000,()=>{
 console.log('服务器启动了')
})
servers.on('request',(request,response)=>{
    const {url,method} = request
    let data = {}
    if(method.toLocaleLowerCase()==='get'){
        if(url === '/api/students'){
            data = bd.getStudents()
        }else if(url === '/api/lucystar'){
            data =bd.lucyStudents()
        }
    }
     //跨域
     response.setHeader('Access-Control-Allow-Origin', '*')
     response.setHeader('Content-Type', 'application/json; charset=utf-8')
      // 不能直接响应 对象/数组 需要转为字符串
      console.log(data)
      response.end(JSON.stringify(data))


})